package com.log6z.dashborad.controller;


import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.hash.Hash;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.log6z.dashborad.domain.AjaxResult;
import com.log6z.dashborad.domain.Appointment;
import com.log6z.dashborad.mapper.AppointmentMapper;
import com.log6z.dashborad.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private AppointmentService appointmentService;

    @Autowired
    private AppointmentMapper appointmentMapper;

    /**
     * 基础数据
     *
     * @return
     */
    @GetMapping("/baseData")
    public AjaxResult baseData() {
        HashMap<String, Object> hash = appointmentService.baseData();
        return AjaxResult.success(hash);
    }


    @GetMapping("/saleCoalTon")
    public AjaxResult saleCoalTon(@RequestParam("queryType") Integer queryType){
        QueryWrapper<Appointment> queryWrapper = new QueryWrapper<>();
        List<Appointment> returnList = new ArrayList<>();

        switch (queryType){
            case 1:
                //当月累计
                returnList = appointmentMapper.saleCoalTonTimeAround(DateUtil.beginOfMonth(DateUtil.date()),DateUtil.endOfMonth(DateUtil.date()));
                break;
            case 2:
                //当年累计
                returnList = appointmentMapper.saleCoalTonTimeAround(DateUtil.beginOfYear(DateUtil.date()),DateUtil.endOfYear(DateUtil.date()));
                break;
            case 3:
                //上月累计
                returnList = appointmentMapper.saleCoalTonTimeAround(DateUtil.beginOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-1)),DateUtil.endOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-1)));
                break;
            case 4:
                //上上月累计
                returnList = appointmentMapper.saleCoalTonTimeAround(DateUtil.beginOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-2)),DateUtil.endOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-2)));
                break;
            case 5:
                //大上月累计
                returnList = appointmentMapper.saleCoalTonTimeAround(DateUtil.beginOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-3)),DateUtil.endOfMonth(DateUtil.offset(DateUtil.date(), DateField.MONTH,-3)));
                break;
            default:
                break;
        }
        return AjaxResult.success(returnList);
    }

    /**
     * --折线图数据
     * @param custId
     * @return
     */
    @GetMapping("/chartEcData")
    public AjaxResult chartEcData(@RequestParam(value = "custId",required = false) Integer custId) {
        HashMap<String, Object> hash = appointmentService.chartEcData(custId);
        return AjaxResult.success(hash);
    }






}
